//浮动JS库
var Floating = 
{
	//divid 内容ID，程序会从HTML中将divid里的内存读取出来存储
	//position 支持以下模式
		//	left top （左上）
		//	left bottom （左下）
		//	right top （右上）
		//	right bottom （右下）
		//	middle middle（中间）
	//margin 间距，表示距浏览器是小边的间距，在 middle 类型表示 距离上面和左侧间距
	init:function(divid,position,margin,zindex)
	{
		var obj = document.getElementById(divid);
		if(!obj || obj == "undefined")
		{
			return false;
		}
		var content = obj.innerHTML;
		if(!content)
		{
			return false;
		}
		if(!zindex)
		{
			zindex = 100;
		}
		Floating.width = obj.style.width ? obj.style.width : "160px";//获取DIV的宽度
		Floating.height = obj.style.height ? obj.style.height : "120px";//DIV的高度
		//比较高度
		var t_height = Floating.height.replace("px","");
		//将display为none去掉
		obj.style.display = "";
		var chk_height = obj.scrollHeight;
		obj.style.display = "none";
		if(t_height < chk_height)
		{
			Floating.height = chk_height + "px";
		}
		Floating.content = content;
		if(!position || position == "undefined")
		{
			position = "right bottom";
		}
		Floating.div_layer(divid,position,margin,zindex);
	},
	div_layer:function(divid,position,margin,zindex)
	{
		var obj_layer = document.createElement("div");
		t_divid = Floating.set_divid(divid);
		//window[t_divid] = "";
		obj_layer.id = t_divid;
		var style = "position:absolute;z-index:"+zindex+";";
		style += "width:"+Floating.width+";height:"+Floating.height+";";
		style += "border:1px solid #0C5870;background:#FFF;";
		var div_width = Floating.width.replace("px","");
		var div_height = Floating.height.replace("px","");
		var pos_array = position.split(" ");
		var pos_1 = pos_array[0] ? pos_array[0] : "right";
		var pos_2 = pos_array[1] ? pos_array[1] : "bottom";
		var margin_array = margin.split(" ");
		var margin_1 = margin_array[0] ? margin_array[0] : "0";
		var margin_2 = margin_array[1] ? margin_array[1] : "0";
		//全局宽度
		var global_width = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
		//全局高度
		var global_height = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		//定义参数检测
		if(pos_1 != "left" && pos_1 != "right" && pos_1 != "middle")
		{
			pos_1 = "right";
		}
		if(pos_2 != "top" && pos_2 != "bottom" && pos_2 != "middle")
		{
			pos_2 = "bottom";
		}
		if(pos_1 != "middle")
		{
			style += pos_1+":"+margin_1+"px;";
		}
		else
		{
			var padding_left = parseInt((global_width - div_width)/2);
			style += "left:"+padding_left+"px;";
		}
		if(pos_2 != "middle")
		{
			style += pos_2+":"+margin_2+"px;";
			if(pos_2 == "top")
			{
				Floating.movestyle[t_divid] = margin_2;
			}
			else
			{
				Floating.movestyle[t_divid] = (parseInt(global_height)-parseInt(div_height)-parseInt(margin_2));
			}
		}
		else
		{
			var padding_top = parseInt((global_height - div_height)/2);
			style += "top:"+padding_top+"px";
			Floating.movestyle[t_divid] = padding_top;
		}
		obj_layer.style.cssText = style;
		obj_layer.innerHTML = Floating.content;
		document.body.appendChild(obj_layer);
	},
	move:function(fid)
	{
		//var tt=50;
		var pos;
		if(document.documentElement && document.documentElement.scrollTop)
		{
			pos = document.documentElement.scrollTop;
		}
		else if(document.body)
		{
			pos = document.body.scrollTop;
		}
		else
		{
			pos = window.pageYOffset;
		}
		mfid = Floating.set_divid(fid);
		var tips = document.getElementById(mfid);
		var movestyle = parseInt(Floating.movestyle[mfid]);
		var scrollTop = parseInt(pos);
		tips.style.top = (scrollTop+ movestyle)+"px";
	},
	start:function(fid,time)
	{
		if(!time || time<1)
		{
			time = 10;
		}
		setInterval("Floating.move('"+fid+"')",time);
	},
	out:function(tid)
	{
		if(!tid)
		{
			return false;
		}
		var delid = Floating.set_divid(tid);
		var obj_id = document.getElementById(delid);
		if(obj_id)
		{
			obj_id.parentNode.removeChild(obj_id);
		}
		return true;
	},
	set_divid:function(tid)
	{
		return tid+"_tmp_1593546428784564423abcdefpiuhjkl";
	},
	set_divarray:function(tid)
	{
		if(!tid)
		{
			return false;
		}
		var array = tid.split(",");
		var movestyle = new Array();
		for(var i = 0;i<array.length;i++)
		{
			movestyle[array[i]] = "";
		}
		Floating.movestyle = movestyle;
	}
}